<!DOCTYPE html>
<html>
<head>
  <title>Apposs</title>
  <%= stylesheet_link_tag :all %>
  <%= stylesheet_link_tag "resources/css/ext-all.css" %>
  <%= javascript_include_tag "ext-all-debug" %>
  <%= javascript_include_tag "ext-lang-zh_CN.js" %>
  <%= javascript_include_tag "jquery.min.js" %>
  <%= javascript_include_tag "utils" %>
  <%= csrf_meta_tag %>
  <style type="text/css">
      .x-grid-row-selected, .x-grid-row-over {
          background: #396295;
      }
  </style>
</head>
<body>
<div id="north">
  <span id="notice"><%= flash[:notice] %><h2>APPOSS管理系统</h2></span>
  <ul id="welcome_info">
    <li><%= current_user.email %>，你好，欢迎使用淘宝运维系统！<%= link_to "退出", '/users/sign_out' %></li>
  </ul>
</div>
<!--
  The following is cmd_operation_model
-->
<script type="text/javascript">
    /**
     * Created by JetBrains RubyMine.
     * User: liupengtao.pt
     * Date: 11-8-1
     * Time: 上午10:44
     * To change this template use File | Settings | File Templates.
     */
//命令Model
//createModel('DirectiveTemplate', ['id','name','alias','arg1','arg2','arg3','arg4','arg5','directive_group_id'], {
//    type:'ajax',
//    url:'/admin/directive_templates',
//    reader:'json',
//    extraParams: {
//        authenticity_token:$('meta[name="csrf-token"]').attr('content')
//    }
//});
    var nsCmdOperation = {};
    nsCmdOperation.PAGE_SIZE = 50;
    Ext.define('DirectiveTemplate', {
        extend:'Ext.data.Model',
        fields:['id','name','alias','arg1','arg2','arg3','arg4','arg5','directive_group_id'],
        proxy:{
            type:'ajax',
            url:"<%= admin_directive_templates_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'directive_templates'
            },
            extraParams: {
                authenticity_token:$('meta[name="csrf-token"]').attr('content')
            }
        }
    });

    //命令的GridPanel Store
    var cmdDefGridStore = Ext.create('Ext.data.Store', {
        model:DirectiveTemplate,
        pageSize:nsCmdOperation.PAGE_SIZE
    });

    //命令组Model
    Ext.define('DirectiveGroup', {
        extend:'Ext.data.Model',
        fields:['id','name'],
        proxy:{
            type:'ajax',
            url:"<%= admin_directive_groups_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'directive_groups'
            }
        }
    });

    //编辑命令中的命令组Combo的Store
    var editDirectiveTemplateDirectiveGroupComboStore = Ext.create('Ext.data.Store', {
        model:DirectiveGroup,
        autoLoad:true
    });
    editDirectiveTemplateDirectiveGroupComboStore.load();
    //增加命令时对应的命令组
    var addDirectiveTemplateDirectiveGroupComboStore = Ext.create('Ext.data.Store', {
        model:DirectiveGroup,
        autoLoad:true
    });
    //编辑命令组中的数据store
    var cmdGroupGridStore = Ext.create('Ext.data.Store', {
        model:DirectiveGroup,
        pageSize:nsCmdOperation.PAGE_SIZE
    });
    cmdGroupGridStore.loadPage(1)
    //命令中的命令组renderer
    function cmdGroupRender(value) {
        var comboRecord = editDirectiveTemplateDirectiveGroupComboStore.getById(value);
        if (comboRecord) {
            return comboRecord.get('name');
        }
        return value;
    }

    var cmdDefPanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });
    var cmdGroupPanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });

</script>
<!--
The following is machine_room_model
-->
<script type="text/javascript">
    /**
     * Created by JetBrains RubyMine.
     * User: liupengtao.pt
     * Date: 11-8-1
     * Time: 上午10:54
     * To change this template use File | Settings | File Templates.
     */
    var nsMachineRoom = {}
    nsMachineRoom.PAGE_SIZE = 50;
    //机器Model
    Ext.define('Machine', {
        extend:'Ext.data.Model',
        fields:['id','name','host','port','adapter','room_id','app_id','user','password'],
        
        proxy:{
            type:'ajax',
            url:"<%= admin_machines_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'machines'
            },
            extraParams: {
                authenticity_token:$('meta[name="csrf-token"]').attr('content')
            }
        }
    });

    //机器的GridPanel Store
    var machineGridStore = Ext.create('Ext.data.Store', {
        pageSize:nsMachineRoom.PAGE_SIZE,
        model:Machine
    });

    //机房Model
    Ext.define('Room', {
        extend:'Ext.data.Model',
        fields:['id','name'],
        proxy:{
            type:'ajax',
            url:"<%= admin_rooms_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'rooms'
            }
        }
    });
    //应用Model
    Ext.define('MachineApp', {
        extend:'Ext.data.Model',
        fields:['id','name'],
        proxy:{
            type:'ajax',
            url:"<%= admin_apps_path %>",
            reader:'json'
        }
    });

    //编辑机器中的机房Combo的Store
    var editMachineRoomComboStore = Ext.create('Ext.data.Store', {
        model:Room,
        autoLoad:true
    });
    editMachineRoomComboStore.load();

    //编辑机器中的机房Combo的Store
    var editMachineAppComboStore = Ext.create('Ext.data.Store', {
        model:MachineApp,
        autoLoad:true
    });
    editMachineAppComboStore.load();

    //增加机器时对应的机房
    var addMachineRoomComboStore = Ext.create('Ext.data.Store', {
        model:Room,
        autoLoad:true
    });
    //增加机器时对应的应用
    var addMachineAppComboStore = Ext.create('Ext.data.Store', {
        model:MachineApp,
        autoLoad:true
    });

    //编辑机房中的数据store
    var roomGridStore = Ext.create('Ext.data.Store', {
        model:Room,
        pageSize:nsMachineRoom.PAGE_SIZE
    });
    roomGridStore.loadPage(1);
    //机器中的机房renderer
    function roomRender(value) {
        var comboRecord = editMachineRoomComboStore.getById(value);
        if (comboRecord) {
            return comboRecord.get('name');
        }
        return value;
    }

    //机器中的应用renderer
    function appRender(value) {
        var comboRecord = editMachineAppComboStore.getById(value);
        if (comboRecord) {
            return comboRecord.get('name');
        }
        return value;
    }

    //机器中的密码renderer
    function passwordRender(value) {
//        if (!value || value.trim().length == 0) {
//            return value;
//        }
        return '<input type="password" style="border: none;" value="' + '......' + '" />';
    }

    var machinePanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });
    var roomPanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });

</script>
<!--
The following is user_role_model
-->
<script type="text/javascript">
    var nsRoleUser = {};
    nsRoleUser.PAGE_SIZE = 50;

    Ext.define('AdminUser', {
        extend:'Ext.data.Model',
        fields:[
            'id',
            'email',
            {name:'current_sign_in_at',type:'date'},
            {name:'last_sign_in_at',type:'date'},
            'current_sign_in_ip',
            'last_sign_in_ip'
        ],
        proxy:{
            type:'ajax',
            url:"<%= admin_users_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'users'
            },
            extraParams: {
                authenticity_token:Ext.select('meta[name="csrf-token"]').elements[0].getAttribute('content')
            },
            limitParam:'per_page'
        }
    });

    Ext.define('Role', {
        extend:'Ext.data.Model',
        fields:['id', 'name'],
        proxy:{
            type:'ajax',
            url:"<%= admin_roles_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'roles'
            },
            extraParams: {
                authenticity_token:$('meta[name="csrf-token"]').attr('content')
            }
        }
    });

    //角色的GridPanel Store
    var roleGridStore = Ext.create('Ext.data.Store', {
        pageSize:nsRoleUser.PAGE_SIZE,
        model:Role
    });

    //用户的GridPanel Store
    var userGridStore = Ext.create('Ext.data.Store', {
        pageSize:nsRoleUser.PAGE_SIZE,
        model:AdminUser
    });

    roleGridStore.loadPage(1);
    userGridStore.loadPage(1);

    var rolePanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });
    var userPanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });
</script>

<!--
   The following is app_model
-->
<script type="text/javascript">
    var nsApp = {};
    nsApp.PAGE_SIZE = 50;
    Ext.define('AdminApp', {
        extend:'Ext.data.Model',
        fields:[
            'id',
            'name',
            {name:'created_at',type:'date'}
        ],
        proxy:{
            type:'ajax',
            url:"<%= admin_apps_path %>",
            reader:{
                type:'json',
                totalProperty:'totalCount',
                root:'apps'
            },
            extraParams: {
                authenticity_token:$('meta[name="csrf-token"]').attr('content')
            },
            limitParam:'per_page'
        }
    });
    //应用的GridPanel Store
    var appGridStore = Ext.create('Ext.data.Store', {
        pageSize:nsApp.PAGE_SIZE,
        sorters: ['id'],
        model:'AdminApp'
    });

    appGridStore.loadPage(1);

    var appPanelRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToEdit: 1
    });
</script>
<%= yield %>

</body>
</html>
